package com.jd.product.controller;

import com.jd.product.dao.TestUserMapper;
import com.jd.product.feign.TestFeign;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/product")
public class TestController {

    @Resource
    private TestFeign testFeign;

    @Autowired
    private TestUserMapper testUserMapper;

    @GetMapping("/addUser")
    public String addUser(@RequestParam String userName){
        try{
            log.info(userName);
            System.out.println(userName+"&&&&&&&&&&&&&&&&&&&");
            testFeign.addDept(userName);
            return userName;
        }catch (Exception e){
            e.printStackTrace();
            log.error("测试出错",e.toString());
            return e.getMessage();
        }
    }

    @GetMapping("/addDept")
    public String addDept(@RequestParam String userName){
        try{
            log.info(userName);
            System.out.println(userName+"&&&&&&&&&&&&&&&&&&&");
//            testFeign.addUser(userName);
            return userName;
        }catch (Exception e){
            e.printStackTrace();
            log.error("测试出错",e.toString());
            return e.getMessage();
        }
    }

    @GetMapping("/queryTotalNum")
    public int queryTotalNum(@RequestParam(required = false) String userName){
        try{
//            log.info(userName);
            System.out.println(userName+"&&&&&");
            int queryTotalNum = testUserMapper.queryTotalNum();
            return queryTotalNum;
        }catch (Exception e){
            e.printStackTrace();
//            log.error("测试出错",e.toString());
            return -1;
        }
    }

}
